Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(js_parser): better diagnostic for infer type #243 #308

Merged
merged 1 commit into from
Sep 18, 2023

Conversation

denbezrukov
Copy link
Contributor

Summary

The 'infer' keyword can only be utilized within the 'extends' clause of a conditional type. Using it outside of this context will result in an error. Ensure that any type declarations using 'infer' are correctly placed within the conditional type structure to avoid parsing issues.

Added an error message from the typescript for such cases:
'infer' declarations are only permitted in the 'extends' clause of a conditional type.

Took test cases from the ts repo:
https://github.com/microsoft/TypeScript/blob/9cbcf010ce0701a25f01a2a074000db34f80cc17/tests/baselines/reference/inferTypes1.errors.txt#L124
https://github.com/microsoft/TypeScript/blob/9cbcf010ce0701a25f01a2a074000db34f80cc17/tests/baselines/reference/templateLiteralTypes1.errors.txt#L5

Test Plan

cargo test

@github-actions github-actions bot added A-Parser Area: parser A-Formatter Area: formatter A-Website Area: website L-JavaScript Language: JavaScript and super languages A-Changelog Area: changelog labels Sep 16, 2023
@denbezrukov denbezrukov temporarily deployed to Website deployment September 16, 2023 21:50 — with GitHub Actions Inactive
@denbezrukov denbezrukov temporarily deployed to Website deployment September 17, 2023 15:30 — with GitHub Actions Inactive
@denbezrukov
Copy link
Contributor Author

!bench_parser

@denbezrukov denbezrukov temporarily deployed to Website deployment September 17, 2023 16:19 — with GitHub Actions Inactive
@denbezrukov
Copy link
Contributor Author

Parser Benchmark Results

group                                          main                                   pr
-----                                          ----                                   --
parser/big5-added.json/cached                  1.01    190.5±3.23µs    88.7 MB/sec    1.00    187.9±1.86µs    89.9 MB/sec
parser/big5-added.json/uncached                1.00    226.5±1.96µs    74.6 MB/sec    1.00    225.8±0.83µs    74.8 MB/sec
parser/canada.json/cached                      1.07    127.9±3.27ms    [16](https://github.com/biomejs/biome/actions/runs/6214415543/job/16866328508#step:10:17).8 MB/sec    1.00    120.0±4.99ms    [17](https://github.com/biomejs/biome/actions/runs/6214415543/job/16866328508#step:10:18).9 MB/sec
parser/canada.json/uncached                    1.04    128.0±2.21ms    16.8 MB/sec    1.00    122.6±2.32ms    17.5 MB/sec
parser/checker.ts/cached                       1.02    146.2±4.73ms    17.8 MB/sec    1.00    142.9±2.47ms    [18](https://github.com/biomejs/biome/actions/runs/6214415543/job/16866328508#step:10:19).2 MB/sec
parser/checker.ts/uncached                     1.02    152.0±1.83ms    17.1 MB/sec    1.00    149.0±2.00ms    17.5 MB/sec
parser/compiler.js/cached                      1.04     86.7±1.59ms    12.1 MB/sec    1.00     83.4±1.73ms    12.6 MB/sec
parser/compiler.js/uncached                    1.04     90.0±1.22ms    11.6 MB/sec    1.00     86.4±1.52ms    12.1 MB/sec
parser/d3.min.js/cached                        1.07     52.1±0.98ms     5.0 MB/sec    1.00     48.6±1.85ms     5.4 MB/sec
parser/d3.min.js/uncached                      1.04     52.2±0.57ms     5.0 MB/sec    1.00     50.1±1.45ms     5.2 MB/sec
parser/db.json/cached                          1.02      5.3±0.04ms    34.5 MB/sec    1.00      5.2±0.04ms    35.3 MB/sec
parser/db.json/uncached                        1.02      5.9±0.06ms    30.8 MB/sec    1.00      5.9±0.06ms    31.3 MB/sec
parser/dojo.js/cached                          1.02      3.9±0.03ms    17.7 MB/sec    1.00      3.8±0.05ms    18.0 MB/sec
parser/dojo.js/uncached                        1.00      4.3±0.02ms    15.9 MB/sec    1.00      4.3±0.06ms    15.9 MB/sec
parser/eucjp.json/cached                       1.01    314.1±5.11µs   124.7 MB/sec    1.00    312.4±2.80µs   125.4 MB/sec
parser/eucjp.json/uncached                     1.00    360.3±1.65µs   108.7 MB/sec    1.00    359.7±1.00µs   108.9 MB/sec
parser/ios.d.ts/cached                         1.02    131.0±1.60ms    14.2 MB/sec    1.00    128.7±1.97ms    14.5 MB/sec
parser/ios.d.ts/uncached                       1.00    133.0±1.65ms    14.0 MB/sec    1.01    133.7±1.91ms    14.0 MB/sec
parser/jquery.min.js/cached                    1.04     12.8±0.18ms     6.4 MB/sec    1.00     12.3±0.22ms     6.7 MB/sec
parser/jquery.min.js/uncached                  1.01     13.4±0.12ms     6.2 MB/sec    1.00     13.3±0.26ms     6.2 MB/sec
parser/math.js/cached                          1.07    105.2±1.71ms     6.2 MB/sec    1.00     98.2±3.90ms     6.6 MB/sec
parser/math.js/uncached                        1.05    104.4±1.17ms     6.2 MB/sec    1.00     99.6±2.04ms     6.5 MB/sec
parser/package-lock.json/cached                1.03      2.2±0.02ms    62.9 MB/sec    1.00      2.1±0.01ms    64.7 MB/sec
parser/package-lock.json/uncached              1.02      2.4±0.02ms    57.8 MB/sec    1.00      2.3±0.01ms    58.9 MB/sec
parser/parser.ts/cached                        1.00      2.8±0.03ms    17.7 MB/sec    1.02      2.8±0.02ms    17.4 MB/sec
parser/parser.ts/uncached                      1.00      3.1±0.02ms    15.7 MB/sec    1.01      3.1±0.03ms    15.5 MB/sec
parser/pixi.min.js/cached                      1.06     66.5±1.79ms     6.6 MB/sec    1.00     62.5±1.96ms     7.0 MB/sec
parser/pixi.min.js/uncached                    1.06     66.9±1.07ms     6.6 MB/sec    1.00     62.9±2.27ms     7.0 MB/sec
parser/react-dom.production.min.js/cached      1.01     17.6±0.38ms     6.6 MB/sec    1.00     17.5±0.48ms     6.6 MB/sec
parser/react-dom.production.min.js/uncached    1.02     18.5±0.26ms     6.2 MB/sec    1.00     18.0±0.32ms     6.4 MB/sec
parser/react.production.min.js/cached          1.00    821.3±6.57µs     7.5 MB/sec    1.00   818.2±11.41µs     7.5 MB/sec
parser/react.production.min.js/uncached        1.00    928.8±1.97µs     6.6 MB/sec    1.00   929.6±11.00µs     6.6 MB/sec
parser/router.ts/cached                        1.00   985.8±10.49µs    24.5 MB/sec    1.01   999.0±12.69µs    24.2 MB/sec
parser/router.ts/uncached                      1.00  1173.8±28.67µs    [20](https://github.com/biomejs/biome/actions/runs/6214415543/job/16866328508#step:10:21).6 MB/sec    1.01  1179.8±10.40µs    20.5 MB/sec
parser/tex-chtml-full.js/cached                1.06    141.9±2.27ms     6.4 MB/sec    1.00    133.8±3.15ms     6.8 MB/sec
parser/tex-chtml-full.js/uncached              1.07    142.8±2.09ms     6.4 MB/sec    1.00    133.8±2.84ms     6.8 MB/sec
parser/three.min.js/cached                     1.10     72.7±0.69ms     8.1 MB/sec    1.00     66.1±2.66ms     8.9 MB/sec
parser/three.min.js/uncached                   1.04     73.7±0.80ms     8.0 MB/sec    1.00     70.8±1.52ms     8.3 MB/sec
parser/typescript.js/cached                    1.03    591.9±6.62ms    16.0 MB/sec    1.00   575.7±10.48ms    16.5 MB/sec
parser/typescript.js/uncached                  1.03    605.0±5.04ms    15.7 MB/sec    1.00    589.9±8.31ms    16.1 MB/sec
parser/vue.global.prod.js/cached               1.09     [22](https://github.com/biomejs/biome/actions/runs/6214415543/job/16866328508#step:10:23).6±0.48ms     5.3 MB/sec    1.00     20.8±0.58ms     5.8 MB/sec
parser/vue.global.prod.js/uncached             1.02     22.7±0.[30](https://github.com/biomejs/biome/actions/runs/6214415543/job/16866328508#step:10:31)ms     5.3 MB/sec    1.00     22.3±0.[47](https://github.com/biomejs/biome/actions/runs/6214415543/job/16866328508#step:10:48)ms     5.4 MB/sec

@denbezrukov denbezrukov temporarily deployed to Website deployment September 17, 2023 16:55 — with GitHub Actions Inactive
@github-actions
Copy link
Contributor

github-actions bot commented Sep 17, 2023

Parser conformance results on

js/262

Test result main count This PR count Difference
Total 48863 48863 0
Passed 47808 47808 0
Failed 1055 1055 0
Panics 0 0 0
Coverage 97.84% 97.84% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 40 40 0
Passed 37 37 0
Failed 3 3 0
Panics 0 0 0
Coverage 92.50% 92.50% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 6212 6212 0
Passed 1764 1764 0
Failed 4448 4448 0
Panics 0 0 0
Coverage 28.40% 28.40% 0.00%

ts/babel

Test result main count This PR count Difference
Total 639 639 0
Passed 573 571 ❌ ⏬ -2
Failed 66 68 ❌ ⏫ +2
Panics 0 0 0
Coverage 89.67% 89.36% -0.31%
🔥 Regression (2):
types/literal-string-4
types/literal-string-4-babel-7

ts/microsoft

Test result main count This PR count Difference
Total 17224 17224 0
Passed 13121 13123 ✅ ⏫ +2
Failed 4103 4101 ✅ ⏬ -2
Panics 0 0 0
Coverage 76.18% 76.19% +0.01%
🎉 Fixed (2):
conformance/types/conditional/inferTypes1.ts
conformance/types/literal/templateLiteralTypes1.ts

@denbezrukov denbezrukov temporarily deployed to Website deployment September 17, 2023 17:46 — with GitHub Actions Inactive
@denbezrukov
Copy link
Contributor Author

Regressions are expected:

types/literal-string-4
types/literal-string-4-babel-7

They have the following code which has a invalid infer usage:

let x: `foo-${infer bar}`;

Copy link
Contributor

@nissy-dev nissy-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making parser behavior stricter!

pnpm-lock.yaml Outdated Show resolved Hide resolved
@denbezrukov denbezrukov temporarily deployed to Website deployment September 18, 2023 08:19 — with GitHub Actions Inactive
@denbezrukov denbezrukov merged commit 206c7a7 into main Sep 18, 2023
@denbezrukov denbezrukov deleted the feat/ts-infer branch September 18, 2023 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Changelog Area: changelog A-Formatter Area: formatter A-Parser Area: parser A-Website Area: website L-JavaScript Language: JavaScript and super languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants